window.app = {
	/**
	 * 后端服务发布的url地址
	 */
	// serverUrl: 'http://192.168.42.248:8080',
	// serverUrl: 'http://192.168.2.221:8080',
	serverUrl: 'http://121.40.216.244',
	
	// serverUrl: 'http://114.215.211.1:8080',

	/**
	 * 图片服务器的url地址
	 */
	// imgServerUrl: 'http://192.168.98.100:88/candywall/',
	imgServerUrl: 'http://114.215.211.1:88/group1/',

	/**
	 * Netty服务后端发布的URL地址
	 */
	// nettyServerUrl: "ws://192.168.0.194:8888/ws",
	// nettyServerUrl: "ws://114.215.211.1:8888/ws",

	/**
	 * 默认头像小图片的路径
	 */
	default_head_portrait_small_url: 'images/default_face.gif',

	/**
	 * 默认头像大图片的路径
	 */
	default_head_portrait_big_url: 'images/default_face.gif',

	/**
	 * 判断字符串是否为空
	 * @param {Object} str
	 * true: 代表不为空
	 * false: 代表为空
	 */
	isNotNull: function(str) {
		if (str != null && str != undefined && str != "") {
			return true;
		}
		return false;
	},
	/**
	 * 封装消息提示框，mui默认的alert提示框不支持居中和自定义图标，
	 * 所以使用h5+中的toast
	 * @param {Object} msg
	 * @param {Object} type
	 */
	showToast: function(msg, type) {
		plus.nativeUI.toast(msg, {
			icon: "images/" + type + ".png",
			verticalAlign: "center"
		});
	},
	/**
	 * 保存用户的全局对象
	 * @param {Object} userinfo
	 */
	setGlobalUserInfo: function(userinfo) {
		var userinfoStr = JSON.stringify(userinfo);
		plus.storage.setItem("userinfo", userinfoStr);
	},
	/**
	 * 获取用户的全局对象
	 * @param {Object} userinfo
	 */
	getGlobalUserInfo: function() {
		return JSON.parse(plus.storage.getItem("userinfo"));
	},
	/**
	 * 登出后，移除用户全局对象
	 */
	userLogout: function() {
		// plus.storage: 本地缓存
		plus.storage.removeItem("userinfo");
	},
	/**
	 * 判断当前设备是否联网
	 */
	isConnectNetWork: function() {
		var connectionStatus = plus.networkinfo.getCurrentType();
		if (connectionStatus == plus.networkinfo.CONNECTION_UNKNOW ||
			connectionStatus == plus.networkinfo.CONNECTION_NONE) {
			return false;
		}
		return true;
	},
	/**
	 * 判断当前的socket状态是否已经连接
	 */
	socketIsReady: function(socket) {
		if (socket != null && socket != undefined && socket.readyState == WebSocket.OPEN) {
			return true;
		}
		return false;
	},
	
	// 文件上传模块
	pickFile: {  
	    //调用原生文件系统管理器并选取文件获取文件地址  
	    PickFile:function(callback, acceptType) { //acceptType为你要查的文件类型"image/*"，"audio/*"，"video/*;image/*"  // intent.setType("image/*");//intent.setType("audio/*"); //选择音频//intent.setType("video/*;image/*"); //选择视频 （mp4 3gp 是android支持的视频格式）  
	        var CODE_REQUEST = 1000;  
	        var main = plus.android.runtimeMainActivity();  
	        if (plus.os.name == 'Android') {  
	            var Intent = plus.android.importClass('android.content.Intent');  
	            var intent = new Intent(Intent.ACTION_GET_CONTENT);  
	            intent.addCategory(Intent.CATEGORY_OPENABLE);  
	            if (acceptType) {  
	                intent.setType(acceptType);  
	            } else {  
	                intent.setType("*/*");  
	            }  
	            var _this = app.pickFile;  
	            main.onActivityResult = function(requestCode, resultCode, data) {  
	                if (requestCode == CODE_REQUEST) {  
	                    var uri = data.getData();  
	                    plus.android.importClass(uri);  
	                    var Build = plus.android.importClass('android.os.Build');  
	                    var isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;  
	
	                    var DocumentsContract = plus.android.importClass('android.provider.DocumentsContract');  
	                    // DocumentProvider  
	                    if (isKitKat && DocumentsContract.isDocumentUri(main, uri)) {  
	                        console.log("版本大于 4.4 ");  
	                        // ExternalStorageProvider  
	                        if ("com.android.externalstorage.documents" == uri.getAuthority()) {  
	                            var docId = DocumentsContract.getDocumentId(uri);  
	                            var split = docId.split(":");  
	                            var type = split[0];  
	
	                            if ("primary" == type) {  
	                                var Environment = plus.android.importClass('android.os.Environment');  
	                                callback(Environment.getExternalStorageDirectory() + "/" + split[1]);  
	                            } else {  
	                                var System = plus.android.importClass('java.lang.System');  
	                                var sdPath = System.getenv("SECONDARY_STORAGE");  
	                                if (sdPath) {  
	                                    callback(sdPath + "/" + split[1]);  
	                                }  
	                            }  
	                        }  
	                        // DownloadsProvider  
	                        else if ("com.android.providers.downloads.documents" == uri.getAuthority()) {  
	                            var id = DocumentsContract.getDocumentId(uri);  
	                            var ContentUris = plus.android.importClass('android.content.ContentUris');  
	                            var contentUri = ContentUris.withAppendedId(  
	                                //    Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));  
	                                Uri.parse("content://downloads/public_downloads"), id);  
	                            callback(_this.getDataColumn(main, contentUri, null, null));  
	                        }  
	                        // MediaProvider  
	                        else if ("com.android.providers.media.documents" == uri.getAuthority()) {  
	                            var docId = DocumentsContract.getDocumentId(uri);  
	                            var split = docId.split(":");  
	                            var type = split[0];  
	
	                            var MediaStore = plus.android.importClass('android.provider.MediaStore');  
	                            if ("image" == type) {  
	                                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;  
	                            } else if ("video" == type) {  
	                                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;  
	                            } else if ("audio" == type) {  
	                                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;  
	                            }  
	
	                            var selection = "_id=?";  
	                            var selectionArgs = new Array();  
	                            selectionArgs[0] = split[1];  
	
	                            callback(_this.getDataColumn(main, contentUri, selection, selectionArgs));  
	                        }  
	                    }  
	                    // MediaStore (and general)  
	                    else if ("content" == uri.getScheme()) {  
	                        callback(_this.getDataColumn(main, uri, null, null));  
	                    }  
	                    // File  
	                    else if ("file" == uri.getScheme()) {  
	                        callback(uri.getPath());  
	                    }  
	                }  
	            }  
	            main.startActivityForResult(intent, CODE_REQUEST);  
	        }  
	    },  
	
	    getDataColumn:function(main, uri, selection, selectionArgs) {  
	        plus.android.importClass(main.getContentResolver());  
	        var cursor = main.getContentResolver().query(uri, ['_data'], selection, selectionArgs,  
	            null);  
	        plus.android.importClass(cursor);  
	        if (cursor != null && cursor.moveToFirst()) {  
	            var column_index = cursor.getColumnIndexOrThrow('_data');  
	            var result = cursor.getString(column_index)  
	            cursor.close();  
	            return result;  
	        }  
	        return null;  
	    }  
	},
	
	// 上传文件模板代码：
	//这里第一个参数是 回调函数，第二个是你要选择的文件类型 "image/*"，"audio/*"，"video/*;image/*"，"*/*"
	/* app.pickFile.PickFile(function(fileSrc){
	    console.log(fileSrc);
		plus.nativeUI.showWaiting("正在上传...");
	    //_this.fileSrc = 'file://' + fileSrc;  
	    // _this.fileSrc = 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/audio/music.mp3'  
	    // 这里就会得到 你选择的文件路径。拿到路径后，你可以用uni.uploadFile  进行上传。  
		var task = plus.uploader.createUpload(app.serverUrl + "/user/upload", 
			{ method:"POST",priority:100 },
			function ( t, status ) {
				plus.nativeUI.closeWaiting();
				// 上传完成
				if ( status == 200 ) { 
					app.showToast("上传成功！", "success");
				} else {
					app.showToast("上传失败：" + status, "error");
				}
			}
		);
		task.addFile(fileSrc, {key:"file"} );
		
		// 从字符串路径中获取文件名
		var fileName = fileSrc.substr(fileSrc.lastIndexOf("/") + 1);
		task.addData("fileName", fileName);
		//task.addEventListener( "statechanged", onStateChanged, false );
		task.start(); */
	//}, '*/*');
	
	/**
	 * @param {Object} applyList
	 * 保存老师所带班级学生网上预约申请列表
	 */
	setOnlineApplyList: function(applyList){
		var onlinepplyList = JSON.stringify(applyList);
		plus.storage.setItem("onlinepplyList", onlinepplyList);
	},
	/**
	 * 获取老师所带班级学生网上预约申请列表
	 * @param {Object} userinfo
	 */
	getOnlineApplyList: function() {
		return JSON.parse(plus.storage.getItem("onlinepplyList"));
	},
	/**
	 * 删除老师所带班级学生网上预约申请列表
	 */
	deleteOnlineApplyList: function() {
		plus.storage.removeItem("onlinepplyList");
	},
	/**
	 * @param {Object} studentReportInfo
	 * 保存学生的实习报告信息
	 */
	setStudentReportInfo: function(studentReportInfoData){
		var studentReportInfo = JSON.stringify(studentReportInfoData);
		plus.storage.setItem("studentReportInfo", studentReportInfo);
	},
	/**
	 * 获取保存的学生的实习报告信息
	 */
	getStudentReportInfo: function() {
		return JSON.parse(plus.storage.getItem("studentReportInfo"));
	},
	/**
	 * 删除保存的学生的实习报告信息
	 */
	deleteStudentReportInfo: function() {
		plus.storage.removeItem("studentReportInfo");
	},
}
